package com.lujianfei.recyclerview.recyclerview_multi_type;

import android.os.Bundle;

import com.lujianfei.recyclerview.R;
import com.lujianfei.recyclerview.adapter.RecyclerAdapter;
import com.lujianfei.recyclerview.adapter.WaterfallBannerAdapter;
import com.lujianfei.recyclerview.entity.ListItem;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

public class WaterfallBannerActivity extends AppCompatActivity {

    RecyclerView recyclerview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view_vertical);
        recyclerview = findViewById(R.id.recyclerview);
        /** 设置列表布局方式 */
        StaggeredGridLayoutManager layoutManager= new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
        recyclerview.setLayoutManager(layoutManager);
        List<ListItem> listItems = genData();
        WaterfallBannerAdapter recyclerAdapter = new WaterfallBannerAdapter(listItems);
        recyclerview.setAdapter(recyclerAdapter);
    }

    private List<ListItem> genData() {
        List<ListItem> listItems = new ArrayList<>();
        int[] color = new int[]{0xffff0000,0xff00ff00,0xff0000ff,0xffffff00};
        listItems.add(new ListItem(WaterfallBannerAdapter.TYPE_ITEM_BANNER,"Banner","Summary",color[2]));
        for (int i = 0; i < 20; i++) {
            listItems.add(new ListItem(WaterfallBannerAdapter.TYPE_ITEM,"Title "+i,"Summary "+i,color[i % 4]));
        }
        return listItems;
    }
}
